<?php

namespace maotool\util;

class RandomUtil
{
    public static function randomEle($list)
    {
        return $list[array_rand($list)];
    }

    public static function randomString($length, $baseString = "abcdefghijklmnopqrstuvwxyz0123456789")
    {
        $content = "";
        for ($i = 0; $i < $length; $i++) {
            $content .= $baseString[rand(0, strlen($baseString) - 1)];
        }
        return $content;
    }

    public static function randomStringUpper($length, $baseString = "abcdefghijklmnopqrstuvwxyz0123456789")
    {
        $content = "";
        for ($i = 0; $i < $length; $i++) {
            $content .= $baseString[rand(0, strlen($baseString) - 1)];
        }
        return strtoupper($content);
    }

    public static function randomStringLower($length, $baseString = "abcdefghijklmnopqrstuvwxyz0123456789")
    {
        $content = "";
        for ($i = 0; $i < $length; $i++) {
            $content .= $baseString[rand(0, strlen($baseString) - 1)];
        }
        return strtolower($content);
    }

    public static function randomStringCase($length, $baseString = "abcdefghijklmnopqrstuvwxyz0123456789")
    {
        $content = "";
        for ($i = 0; $i < $length; $i++) {
            $content .= rand(0, 1) == 1 ? strtolower($baseString[rand(0, strlen($baseString) - 1)]) : strtoupper($baseString[rand(0, strlen($baseString) - 1)]);
        }
        return $content;
    }

    public static function randomBoolean()
    {
        return (bool)rand(0, 1);
    }

}